package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.RestBean;
import com.hs.entity.dto.Notice;
import com.hs.entity.dto.Team;
import com.hs.service.TeamService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/api/team")
public class TeamController {
    @Resource
    private TeamService teamService;

    @GetMapping("/getTeamList/{currentNum}")
    public RestBean<PageInfo<Team>> getTeamList(
            @PathVariable("currentNum") Integer currentNum,
            @RequestParam(required = false) String keywords) {
        PageInfo<Team> teamList = teamService.selectTeamList(currentNum,keywords);
        return RestBean.success(teamList);
    }

    @GetMapping("/getTeamById/{id}")
    public RestBean<Team> getTeamById(@PathVariable Integer id) {
//        System.out.println(id);

        Team team = teamService.getById(id);
        return RestBean.success(team);
    }

    @GetMapping("/getAllTeamList")
    public RestBean<List<Team>> getAllTeamList() {

        List<Team> list = teamService.list();
        return RestBean.success(list);
    }

    @PostMapping("/updateTeam")
    public RestBean<Team> updateTeam( @RequestBody Team team) {
        System.out.println(team);
        teamService.updateById(team);
        return RestBean.success(null);
    }

    @PostMapping("/addTeam")
    public RestBean<Team> addTeam( @RequestBody Team team) {
        team.setCreate_time(LocalDateTime.now());
        teamService.save(team);
        return RestBean.success(null);
    }

    @PostMapping("/deleteTeam/{id}")
    public RestBean<Team> deleteTeam(@PathVariable  Integer id) {
        teamService.removeById(id);
        return RestBean.success(null);
    }
}
